package com.lb.uts.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.servlet.MultipartConfigElement;

/**
 * 描述：实现静态资源的过滤
 * 作者：liangb
 * 日期：2018/10/29
 * 时间：17:27
 */
@Configuration
public class UtsMvcConfig implements WebMvcConfigurer {

    @Value("${sso.excludes:''}")
    private String excludes;

    public UtsMvcConfig() {
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //registry.addInterceptor(this.userLoginInterceptor).excludePathPatterns(new String[]{"/sso/loginCon", "/sso/goLogin", "/sso/logout", "/sso/noPermission",""}).excludePathPatterns(this.excludes.split(",")).addPathPatterns("/**");
    }


    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/sso/**").addResourceLocations("classpath:/static/sso/");
        registry.addResourceHandler("/static/**").addResourceLocations("classpath:/static/");
        registry.addResourceHandler("/static/js/3rd/**").addResourceLocations("classpath:/static/js/3rd/");
        registry.addResourceHandler("/images/**").addResourceLocations("classpath:/static/images/");
        registry.addResourceHandler("/css/**").addResourceLocations("classpath:/static/css/");
        registry.addResourceHandler("/js/**").addResourceLocations("classpath:/static/js/");
    }

    /**
     * @return
     * @Title: multipartConfigElement
     * @Description: 文件上传配置
     * @author hut
     * @date 2019年4月19日
     */
    @Bean
    public MultipartConfigElement multipartConfigElement() {
        MultipartConfigFactory factory = new MultipartConfigFactory();
        //  单个数据大小
        factory.setMaxFileSize("10240KB");
        /// 总上传数据大小
        factory.setMaxRequestSize("102400KB");
        return factory.createMultipartConfig();
    }
}
